package cn.wolfcode.rbac.utils;

import lombok.*;

@AllArgsConstructor
@NoArgsConstructor
@Data
public class R {
    private Integer code;  //响应状态码
    private String msg;    //响应提示信息
    private String status; //状态
    private Object data;   //数据

    //code 状态码
    //成功 200
    private static final Integer SUCCESS_CODE = 200;
    //认证失败 401
    private static final Integer AUTHENTICATION_CODE = 401;
    //无权限操作 403
    private static final Integer PERMISSION_CODE = 403;
    //异常 500
    private static final Integer FAIL_CODE = 500;

    private static final String SUCCESS = "success";
    private static final String FAIL = "fail";

    public static R ok(){
        return new R(SUCCESS_CODE, "", SUCCESS, null);
    }

    public static R ok(String msg){
        return new R(SUCCESS_CODE, msg, SUCCESS, null);
    }

    public static R ok(Object data){
        return new R(SUCCESS_CODE, "", SUCCESS, data);
    }

    public static R ok(String msg,Object data){
        return new R(SUCCESS_CODE, msg, SUCCESS, data);
    }

    public static R fail(){
        return new R(FAIL_CODE,"",FAIL,null);
    }

    public static R fail(String msg){
        return new R(FAIL_CODE,msg,FAIL,null);
    }

    public static R fail(Object data){
        return new R(FAIL_CODE,"",FAIL,data);
    }

    public static R fail(String msg,Object data){
        return new R(FAIL_CODE,msg,FAIL,data);
    }

    public static R fail(Integer code,String msg){
        return new R(code,msg,FAIL,null);
    }
}
